#include "udpsock.hpp"

int main(int argc,char* argv[])
{  
 if(argc!=3){
   std::cout<<"usage: ./cli_udp 192.168.26.168 9000\n";
   return -1;
 }
 std::string srv_ip=argv[1];
 uint16_t srv_port=std::stoi(argv[2]);     //将端口信息转换为整型

 UdpSocket cli_sock;
 assert(cli_sock.Socket()==true);  //创建套接字
 
 //客户端不建议绑定地址信息
  
 //循环收发数据
 while(1){
   std::string data;
   std::cout<<"client say: ";
   fflush(stdout);         //发送数据
   std::cin>>data;
   assert(cli_sock.Send(data,srv_ip,srv_port));

   data.clear();
   assert(cli_sock.Recv(&data));   //接收数据
   std::cout<<"serve say: "<<data<<std::endl;
 }
  //关闭套接字
  cli_sock.Close();
 return 0;
}
